home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Table / Sources / TblTrckr.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  9.3 KB  |  317 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                TblTrckr.cpp
  4. //    Release Version:    $ 1.0d11 $ 
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. #ifndef TBLTRCKR_H
  13. #include "TblTrckr.h"
  14. #endif
  15.  
  16. #ifndef TBLPART_H
  17. #include "TblPart.h"
  18. #endif
  19.  
  20. #ifndef TBLFRAME_H
  21. #include "TblFrame.h"
  22. #endif
  23.  
  24. // ----- Part Layer -----
  25.  
  26. #ifndef FWUTIL_H
  27. #include "FWUtil.h"
  28. #endif
  29.  
  30. // ----- OS Layer -----
  31.  
  32. #ifndef FWODGEOM_H
  33. #include "FWODGeom.h"
  34. #endif
  35.  
  36. #ifndef FWACQUIR_H
  37. #include "FWAcquir.h"
  38. #endif
  39.  
  40. #ifndef FWPOINT_H
  41. #include "FWPoint.h"
  42. #endif
  43.  
  44. // ----- OpenDoc Layer -----
  45.  
  46. #ifndef SOM_ODSession_xh
  47. #include <ODSessn.xh>
  48. #endif
  49.  
  50. #ifndef SOM_ODDragAndDrop_xh
  51. #include <DragDrp.xh>
  52. #endif
  53.  
  54. //========================================================================================
  55. // RunTime Info
  56. //========================================================================================
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #pragma segment odfTable
  60. #endif
  61.  
  62. //========================================================================================
  63. //    class CTableDropTracker
  64. //========================================================================================
  65.  
  66. //----------------------------------------------------------------------------------------
  67. //    CTableDropTracker::CTableDropTracker
  68. //----------------------------------------------------------------------------------------
  69.  
  70. CTableDropTracker::CTableDropTracker(Environment* ev, 
  71.                                     CTablePart* part,
  72.                                     CTableFrame* frame,
  73.                                     ODFacet* facet,
  74.                                     const CCell& sourceCell) :
  75.     FW_CDropTracker(ev, frame, facet),
  76.     fTableFrame(frame),
  77.     fTablePart(part),
  78.     fSourceCell(sourceCell),
  79.     fCurCell(-1, -1)
  80. {
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    CTableDropTracker::~CTableDropTracker
  85. //----------------------------------------------------------------------------------------
  86.  
  87. CTableDropTracker::~CTableDropTracker()
  88. {
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    CTableDropTracker::BeginTracking
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CPoint CTableDropTracker::BeginTracking(Environment* ev, 
  96.                                             const FW_CPoint& anchorPoint)
  97. {
  98.     CCell cell;
  99.     
  100.     if (fTablePart->HitTest(ev, fTableFrame, anchorPoint, cell) == kTLCell)
  101.         Hilite(ev, cell, GetFacet(ev));
  102.         
  103.     return anchorPoint;
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    CTableDropTracker::ContinueTracking
  108. //----------------------------------------------------------------------------------------
  109.  
  110. FW_CPoint CTableDropTracker::ContinueTracking(Environment* ev,
  111.                                                 const FW_CPoint& anchorPoint, 
  112.                                                 const FW_CPoint& previousPoint, 
  113.                                                 const FW_CPoint& currentPoint)
  114. {
  115.     CCell cell;
  116.     if (fTablePart->HitTest(ev, fTableFrame, currentPoint, cell) == kTLCell)
  117.         Hilite(ev, cell, GetFacet(ev));
  118.     
  119.     return currentPoint;
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CTableDropTracker::Hilite
  124. //----------------------------------------------------------------------------------------
  125.  
  126. void CTableDropTracker::Hilite(Environment* ev, const CCell& cell, ODFacet* facet)
  127. {
  128.     if (cell == fCurCell)
  129.         return;
  130.     
  131. #ifdef FW_BUILD_MAC
  132.     this->HideDragHilite(ev);
  133.  
  134.     FW_CWindowContext gc(ev, facet);        // focus drawing to the window
  135.  
  136.     DragReference theDrag = fTablePart->GetSession(ev)->GetDragAndDrop(ev)->GetDragReference(ev);
  137.     
  138.     if (cell != fSourceCell)
  139.     {    
  140.         fCurCell = cell;
  141.         
  142.         FW_CRect cellRect;
  143.         fTablePart->FindRect(cell, cellRect);
  144.         
  145.         FW_CRect shapeBounds = fTableFrame->GetBounds(ev);
  146.         FW_CAcquiredODTransform aqInternalXForm = fTableFrame->AcquireInternalTransform(ev, NULL);
  147.         shapeBounds.Transform(ev, aqInternalXForm);
  148.         cellRect.Intersection(shapeBounds);
  149.         
  150.         FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, cellRect);
  151.  
  152.         this->ShowDragHilite(ev, aqShape, TRUE);
  153.     }
  154. #endif
  155. }
  156.  
  157. //========================================================================================
  158. //    class CGridLineTracker
  159. //========================================================================================
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    CGridLineTracker constructor
  163. //----------------------------------------------------------------------------------------
  164. CGridLineTracker::CGridLineTracker(Environment* ev, 
  165.                                      FW_CView* view,
  166.                                     ODFacet* facet,
  167.                                        ETableLoc tl,
  168.                                        FW_CRect dragArea,
  169.                                        FW_CPoint borders) :
  170.     FW_CTracker(ev, view, facet),
  171.     fDragArea(dragArea),
  172.     fOldBorders(borders),
  173.     fNewBorders(borders),
  174.     fCross(borders, dragArea.BotRight())
  175. {
  176.     // Get direction of resize
  177.     fHorizMove = ((tl & (kTLLeftBorder + kTLRightBorder)) != 0);
  178.     fVertMove = ((tl & (kTLTopBorder + kTLBottomBorder)) != 0);
  179.  
  180.     if (fHorizMove)
  181.         fCross.SetVLineToMove();
  182.     if (fVertMove)
  183.         fCross.SetHLineToMove();
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    CGridLineTracker destructor
  188. //----------------------------------------------------------------------------------------
  189. CGridLineTracker::~CGridLineTracker()
  190. {
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    CGridLineTracker::BeginTracking
  195. //----------------------------------------------------------------------------------------
  196. FW_CPoint CGridLineTracker::BeginTracking(Environment* ev, 
  197.                                           const FW_CPoint& anchorPoint)
  198. {
  199.     // Display borders that are moving
  200.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  201.     fCross.Render(vc);
  202.  
  203.     return anchorPoint;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    CGridLineTracker::ContinueTracking
  208. //----------------------------------------------------------------------------------------
  209. FW_CPoint CGridLineTracker::ContinueTracking(Environment* ev,
  210.                                              const FW_CPoint& anchorPoint, 
  211.                                              const FW_CPoint& previousPoint, 
  212.                                              const FW_CPoint& currentPoint)
  213. {
  214.     FW_UNUSED(anchorPoint);
  215.     FW_CPoint now(currentPoint);
  216.  
  217.     // Stay in permissible drag area
  218.     if (now.x < fDragArea.left)
  219.         now.x = fDragArea.left;
  220.     if (now.x > fDragArea.right)
  221.         now.x = fDragArea.right;
  222.     if (now.y < fDragArea.top)
  223.         now.y = fDragArea.top;
  224.     if (now.y > fDragArea.bottom)
  225.         now.y = fDragArea.bottom;
  226.  
  227.     // Move the borders
  228.     if (now != previousPoint)
  229.     {
  230.         FW_CFixed x = (fHorizMove ? now.x - previousPoint.x : FW_IntToFixed(0));
  231.         FW_CFixed y = (fVertMove ? now.y - previousPoint.y : FW_IntToFixed(0));
  232.         
  233.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  234.         fCross.Render(vc);
  235.         fCross.MoveShape(x, y);
  236.         fCross.Render(vc);
  237.         
  238.         fNewBorders.x += x;
  239.         fNewBorders.y += y;
  240.     }
  241.  
  242.     return now;
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    CGridLineTracker::EndTracking
  247. //----------------------------------------------------------------------------------------
  248. FW_Boolean CGridLineTracker::EndTracking(Environment* ev,
  249.                                          const FW_CPoint& anchorPoint, 
  250.                                          const FW_CPoint& lastPoint)
  251. {
  252.     // Restore the borders
  253.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  254.     fCross.Render(vc);
  255.  
  256.     return anchorPoint != lastPoint;
  257. }
  258.  
  259. //========================================================================================
  260. //    class CCrossShape
  261. //========================================================================================
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    CCrossShape::CCrossShape
  265. //----------------------------------------------------------------------------------------
  266.  
  267. CCrossShape::CCrossShape(const FW_CPoint& brCell, FW_CPoint& brFrm)
  268.     : vLine(brCell.x, kHMargin, brCell.x, brFrm.y),
  269.       hLine(kVMargin, brCell.y, brFrm.x, brCell.y)
  270. {
  271.     vLine.SetInk(FW_kInvertInk);
  272.     hLine.SetInk(FW_kInvertInk);
  273.     
  274.     vLine.SetRenderVerb(FW_kNoRendering);
  275.     hLine.SetRenderVerb(FW_kNoRendering);
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //    CCrossShape::Render
  280. //----------------------------------------------------------------------------------------
  281.  
  282. void CCrossShape::Render(FW_CGraphicContext& graphicContext)
  283. {
  284.     vLine.Render(graphicContext);
  285.     hLine.Render(graphicContext);
  286. }
  287.  
  288. //----------------------------------------------------------------------------------------
  289. //    CCrossShape::MoveShape
  290. //----------------------------------------------------------------------------------------
  291.  
  292. void CCrossShape::MoveShape(FW_CFixed deltaX, FW_CFixed deltaY)
  293. {
  294.     vLine.MoveShape(deltaX, FW_IntToFixed(0));
  295.     hLine.MoveShape(FW_IntToFixed(0), deltaY);
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. //    CCrossShape::SetHLineToMove
  300. //----------------------------------------------------------------------------------------
  301.  
  302. void CCrossShape::SetHLineToMove()
  303. {
  304.     hLine.SetRenderVerb(FW_kFrame);
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    CCrossShape::SetVLineToMove
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void CCrossShape::SetVLineToMove()
  312. {
  313.     vLine.SetRenderVerb(FW_kFrame);
  314. }
  315.  
  316.  
  317.